> irb >> 1 => 1 >> 1+1 => 2 >> "hello" => "hello" >> puts "hello" hello => nil >> def inrc n >> n+1 >> end => nil >> inrc 3 => 4 >> "hello".length => 5 >> "hello".reverse => "olleh" >> "hello".class => String >> String.class => Class >> "hello".class.class => Class >> String.methods => ["private_class_method", "inspect", "name", "tap", "clone", "public_methods", "__send__", "method_defined?", "yaml_tag_subclasses?", "instance_variable_defined?", "autoload", "equal?", "freeze", "extend", "send", "const_defined?", "methods", "ancestors", "module_eval", "inrc", "hash", "dup", "object_id", "instance_methods", "public_method_defined?", "taguri", "instance_variables", "class_variable_defined?", "eql?", "yaml_as", "constants", "taguri=", "id", "instance_eval", "singleton_methods", "module_exec", "instance_method", "const_missing", "taint", "autoload?", "instance_variable_get", "frozen?", "to_enum", "private_method_defined?", "to_yaml_style", "public_instance_methods", "display", "instance_of?", "superclass", "to_a", "included_modules", "yaml_new", "const_get", "instance_exec", "type", "<", "protected_methods", "<=>", "class_eval", "==", "class_variables", ">", "===", "instance_variable_set", "enum_for", "yaml_tag_read_class", "protected_instance_methods", "protected_method_defined?", "respond_to?", "kind_of?", ">=", "method", "public_class_method", "yaml_tag_class_name", "to_s", "<=", "const_set", "allocate", "to_yaml", "class", "new", "private_methods", "=~", "tainted?", "__id__", "class_exec", "to_yaml_properties", "untaint", "nil?", "private_instance_methods", "include?", "is_a?"] >> String.methods.class => Array >> String.methods.length => 92 >> Array.methods => ["private_class_method", "inspect", "name", "tap", "clone", "public_methods", "__send__", "method_defined?", "yaml_tag_subclasses?", "instance_variable_defined?", "autoload", "equal?", "freeze", "extend", "send", "const_defined?", "methods", "ancestors", "module_eval", "inrc", "hash", "dup", "object_id", "instance_methods", "public_method_defined?", "taguri", "instance_variables", "class_variable_defined?", "eql?", "yaml_as", "constants", "taguri=", "id", "instance_eval", "singleton_methods", "module_exec", "instance_method", "const_missing", "taint", "autoload?", "instance_variable_get", "frozen?", "to_enum", "private_method_defined?", "to_yaml_style", "public_instance_methods", "display", "instance_of?", "superclass", "to_a", "included_modules", "const_get", "instance_exec", "type", "<", "protected_methods", "<=>", "class_eval", "==", "class_variables", ">", "===", "instance_variable_set", "enum_for", "yaml_tag_read_class", "protected_instance_methods", "protected_method_defined?", "respond_to?", "kind_of?", ">=", "method", "public_class_method", "yaml_tag_class_name", "to_s", "<=", "const_set", "allocate", "to_yaml", "class", "new", "private_methods", "=~", "tainted?", "__id__", "class_exec", "to_yaml_properties", "untaint", "nil?", "private_instance_methods", "include?", "is_a?", "[]"] >> Array.methods.length => 92 >> 1.+(1) => 2 >> 1.+ 1 => 2 >> 1.class => Fixnum >> 1.methods => ["%", "odd?", "lcm", "inspect", "prec_i", "power!", "<<", "tap", "div", "&", "clone", ">>", "public_methods", "__send__", "instance_variable_defined?", "denominator", "equal?", "freeze", "to_sym", "*", "ord", "+", "extend", "next", "send", "round", "methods", "prec_f", "-", "even?", "gcdlcm", "singleton_method_added", "divmod", "inrc", "hash", "/", "integer?", "downto", "gcd", "dup", "object_id", "taguri", "instance_variables", "|", "eql?", "size", "taguri=", "id", "instance_eval", "truncate", "~", "to_r", "to_i", "singleton_methods", "rdiv", "modulo", "taint", "zero?", "times", "instance_variable_get", "frozen?", "to_enum", "to_yaml_style", "display", "instance_of?", "^", "to_a", "numerator", "+@", "-@", "quo", "instance_exec", "type", "**", "upto", "to_f", "<", "step", "protected_methods", "rpower", "<=>", "between?", "==", "remainder", ">", "===", "to_int", "nonzero?", "pred", "instance_variable_set", "enum_for", "coerce", "respond_to?", "kind_of?", "floor", "succ", ">=", "method", "prec", "to_s", "<=", "fdiv", "to_yaml", "class", "private_methods", "=~", "tainted?", "__id__", "to_yaml_properties", "abs", "untaint", "nil?", "chr", "id2name", "is_a?", "ceil", "[]"] >> 3.times { puts "again" } again again again => 3 >> 3.times { |n| puts n } 0 1 2 => 3 >> a = nil => nil >> a => nil >> a.class => NilClass >> a.class.methods => ["private_class_method", "inspect", "name", "tap", "clone", "public_methods", "__send__", "method_defined?", "yaml_tag_subclasses?", "instance_variable_defined?", "autoload", "equal?", "freeze", "extend", "send", "const_defined?", "methods", "ancestors", "module_eval", "inrc", "hash", "dup", "object_id", "instance_methods", "public_method_defined?", "taguri", "instance_variables", "class_variable_defined?", "eql?", "yaml_as", "constants", "taguri=", "id", "instance_eval", "singleton_methods", "module_exec", "instance_method", "const_missing", "taint", "autoload?", "instance_variable_get", "frozen?", "to_enum", "private_method_defined?", "to_yaml_style", "public_instance_methods", "display", "instance_of?", "superclass", "to_a", "included_modules", "const_get", "instance_exec", "type", "<", "protected_methods", "<=>", "class_eval", "==", "class_variables", ">", "===", "instance_variable_set", "enum_for", "yaml_tag_read_class", "protected_instance_methods", "protected_method_defined?", "respond_to?", "kind_of?", ">=", "method", "public_class_method", "yaml_tag_class_name", "to_s", "<=", "const_set", "allocate", "to_yaml", "class", "private_methods", "=~", "tainted?", "__id__", "class_exec", "to_yaml_properties", "untaint", "nil?", "private_instance_methods", "include?", "is_a?"] >> nil.methods.length => 56 >> a=[1,2,3] => [1, 2, 3] >> a => [1, 2, 3] >> a.class => Array >> a.length => 3 >> a[0] => 1 >> a[2] => 3 >> a[3]=4 => 4 >> a => [1, 2, 3, 4] >> a[-2] => 3 >> a[10]=17 => 17 >> a => [1, 2, 3, 4, nil, nil, nil, nil, nil, nil, 17] >> h = { "weather" => "cold" , "xyzzy" => 42 } => {"xyzzy"=>42, "weather"=>"cold"} >> h["weather"] => "cold" >> h["stuff"] = "something interesting" => "something interesting" >> h => {"stuff"=>"something interesting", "xyzzy"=>42, "weather"=>"cold"} >> h.each { |k,v| puts k; puts v } stuff something interesting xyzzy 42 weather cold => {"stuff"=>"something interesting", "xyzzy"=>42, "weather"=>"cold"} >> class Toy >> def initialize(name,color) >> @name=name >> @color = color >> end >> def name >> @name >> end >> end => nil >> truck = Toy.new("firetruck", "red") => # >> truck => # >> truck.name => "firetruck" >> name.color NameError: undefined local variable or method `name' for main:Object from (irb):62 >> class Toy >> def color >> @color >> end >> end => nil >> Toy.methods => ["private_class_method", "inspect", "name", "tap", "clone", "public_methods", "__send__", "method_defined?", "yaml_tag_subclasses?", "instance_variable_defined?", "autoload", "equal?", "freeze", "extend", "send", "const_defined?", "methods", "ancestors", "module_eval", "inrc", "hash", "dup", "object_id", "instance_methods", "public_method_defined?", "taguri", "instance_variables", "class_variable_defined?", "eql?", "yaml_as", "constants", "taguri=", "id", "instance_eval", "singleton_methods", "module_exec", "instance_method", "const_missing", "taint", "autoload?", "instance_variable_get", "frozen?", "to_enum", "private_method_defined?", "to_yaml_style", "public_instance_methods", "display", "instance_of?", "superclass", "to_a", "included_modules", "const_get", "instance_exec", "type", "<", "protected_methods", "<=>", "class_eval", "==", "class_variables", ">", "===", "instance_variable_set", "enum_for", "yaml_tag_read_class", "protected_instance_methods", "protected_method_defined?", "respond_to?", "kind_of?", ">=", "method", "public_class_method", "yaml_tag_class_name", "to_s", "<=", "const_set", "allocate", "to_yaml", "class", "new", "private_methods", "=~", "tainted?", "__id__", "class_exec", "to_yaml_properties", "untaint", "nil?", "private_instance_methods", "include?", "is_a?"] >> truck => # >> truck.name => "firetruck" >> truck.color => "red" >> truck.color="green" NoMethodError: undefined method `color=' for # from (irb):77 >> class Toy >> def color=(color) >> @color=color >> end >> end => nil >> truck => # >> truck.color => "red" >> truck.color="purple" => "purple" >> truck => # >> 1.class => Fixnum >> 1.methods => ["%", "odd?", "lcm", "inspect", "prec_i", "power!", "<<", "tap", "div", "&", "clone", ">>", "public_methods", "__send__", "instance_variable_defined?", "denominator", "equal?", "freeze", "to_sym", "*", "ord", "+", "extend", "next", "send", "round", "methods", "prec_f", "-", "even?", "gcdlcm", "singleton_method_added", "divmod", "inrc", "hash", "/", "integer?", "downto", "gcd", "dup", "object_id", "taguri", "instance_variables", "|", "eql?", "size", "taguri=", "id", "instance_eval", "truncate", "~", "to_r", "to_i", "singleton_methods", "rdiv", "modulo", "taint", "zero?", "times", "instance_variable_get", "frozen?", "to_enum", "to_yaml_style", "display", "instance_of?", "^", "to_a", "numerator", "+@", "-@", "quo", "instance_exec", "type", "**", "upto", "to_f", "<", "step", "protected_methods", "rpower", "<=>", "between?", "==", "remainder", ">", "===", "to_int", "nonzero?", "pred", "instance_variable_set", "enum_for", "coerce", "respond_to?", "kind_of?", "floor", "succ", ">=", "method", "prec", "to_s", "<=", "fdiv", "to_yaml", "class", "private_methods", "=~", "tainted?", "__id__", "to_yaml_properties", "abs", "untaint", "nil?", "chr", "id2name", "is_a?", "ceil", "[]"] >> class Fixnum >> def +(other) >> 17 >> end >> end => nil >> 1+1 => 17 >> 2+3 => 17 >> a => [1, 2, 3, 4, nil, nil, nil, nil, nil, nil, 17] >> a[1+1]="what?" >> a >> a >> a >> ^D=> [1, 2, 3, 4, nil, nil, nil, nil, nil, nil, 17, nil, nil, nil, nil, nil, nil, "what?"] >